const request = require("./http.js");

var addBack = function (data, callback) {
    request({
        url: "/mall/customerBankCard/insertCard",
        method: "post",
        data: data,
        success: function (res) {
            callback(res);
        },
        fail: function (err) {
            wx.showToast({
                title: err.errMsg,
                icon: "none",
                duration: 2000,
            });
        },
    });
};

var getMyBankList = function (id, callback) {
    request({
        url: "/mall/customerBankCard/bankList?customerId=" + id,
        method: "get",
        success: function (res) {
            callback(res);
        },
        fail: function (err) {
            wx.showToast({
                title: err.errMsg,
                icon: "none",
                duration: 2000,
            });
        },
    });
};


var getCurrentLottery = function (id, callback) {
    request({
        url: "/mall/lotteryTurntable/CurrentLottery?customerId=" + id,
        method: "get",
        success: function (res) {
            callback(res);
        },
        fail: function (err) {
            wx.showToast({
                title: err.errMsg,
                icon: "none",
                duration: 2000,
            });
        },
    });
};


const startLottery = function (data, callback) {
    request({
        url: "/mall/winningRecord/letsLottery",
        method: "post",
        data: data,
        success: function (res) {
            callback(res);
        },
        fail: function (err) {
            wx.showToast({
                title: err.errMsg,
                icon: "none",
                duration: 2000,
            });
        },
    });
}


const getCommodityCategory = function (data, callback) {
    request({
        url: "/mall/tbSpu/getCommodityCategory",
        method: "post",
        data: data,
        success: function (res) {
            callback(res);
        },
        fail: function (err) {
            wx.showToast({
                title: err.errMsg,
                icon: "none",
                duration: 2000,
            });
        },
    });

}

const tAgentAdd = function (data, callback) {
    request({
        url: "/mall/tAgent/add",
        method: "post",
        data: data,
        success: function (res) {
            callback(res);
        },
        fail: function (err) {
            wx.showToast({
                title: err.errMsg,
                icon: "none",
                duration: 2000,
            });
        },
    });
}

const getMyAgentList = function (data, callback) {
    request({
        url: "/mall/tAgent/myAgentList",
        method: "post",
        data: data,
        success: function (res) {
            callback(res);
        },
        fail: function (err) {
            console.log(111, err)
            wx.showToast({
                title: err.errMsg,
                icon: "none",
                duration: 2000,
            });
        },
    });
}


const getMyCustomerList = function (data, callback) {
    request({
        url: "/mall/tAgent/myCustomerList",
        method: "post",
        data: data,
        success: function (res) {
            callback(res);
        },
        fail: function (err) {
            console.log(111, err)
            wx.showToast({
                title: err.errMsg,
                icon: "none",
                duration: 2000,
            });
        },
    });
}


const getAgentTypeList = function (data, callback) {
    request({
        url: "/mall/tAgent/agentTypeList",
        method: "post",
        data: data,
        success: function (res) {
            callback(res);
        },
        fail: function (err) {
            console.log(111, err)
            wx.showToast({
                title: err.errMsg,
                icon: "none",
                duration: 2000,
            });
        },
    });
}

const delBankCard = function (id, callback) {
    request({
        url: "/mall/customerBankCard/delBankCard?cardId=" + id,
        method: "get",
        success: function (res) {
            callback(res);
        },
        fail: function (err) {
            console.log(111, err)
            wx.showToast({
                title: err.errMsg,
                icon: "none",
                duration: 2000,
            });
        },
    });
}


const getOverallBalance = function (data, callback) {
    request({
        url: "/mall/withdrawalapplication/overallBalance",
        method: "post",
        data: data,
        success: function (res) {
            callback(res);
        },
        fail: function (err) {
            console.log(111, err)
            wx.showToast({
                title: err.errMsg,
                icon: "none",
                duration: 2000,
            });
        },
    });
}

//查看提现列表

const getWithdraw = function (data, callback) {
    request({
        url: "/mall/withdrawalapplication/withdraw",
        method: "post",
        data: data,
        success: function (res) {
            callback(res);
        },
        fail: function (err) {
            console.log(111, err)
            wx.showToast({
                title: err.errMsg,
                icon: "none",
                duration: 2000,
            });
        },
    });
}

const bindSubmit = function (data, callback) {
    request({
        url: "/mall/withdrawalapplication/submit",
        method: "post",
        data: data,
        success: function (res) {
            callback(res);
        },
        fail: function (err) {
            console.log(111, err)
            wx.showToast({
                title: err.errMsg,
                icon: "none",
                duration: 2000,
            });
        },
    });
}


const getMinimumMoney = function (callback) {
    request({
        url: "/mall/withdrawalapplication/minimumMoney",
        method: "get",
        success: function (res) {
            callback(res);
        },
        fail: function (err) {
            console.log(111, err)
            wx.showToast({
                title: err.errMsg,
                icon: "none",
                duration: 2000,
            });
        },
    });
}


const getGoodsQrCode = function (id, callback) {
    request({
        url: "/mall/owner/shareGoods?id=" + id,
        method: "post",
        data: {
            id
        },
        success: function (res) {
            callback(res);
        },
        fail: function (err) {
            console.log(111, err)
            wx.showToast({
                title: err.errMsg,
                icon: "none",
                duration: 2000,
            });
        },
    });
}
const getGoodpercent = (id,callback) => {
    request({
        url: "/mall/tAgent/showCommodityAgencyPercentage?spuId="+id,
        method: "get",
        success: function (res) {
            callback(res);
        },
        fail: function (err) {
            //console.log(111, err)
            wx.showToast({
                title: err.errMsg,
                icon: "none",
                duration: 2000,
            });
        },
    });
};
// 支付失败退款
const returnMoney = (orderId, callback) => {
    request({
        url: '/mall/membershipRecord/update',
        method: 'post',
        data: {
            orderId,
            status: 0
        },
        success (res) {
            callback(res)
        },
        fail (err) {
            wx.showToast({
                title: err.errMsg || '服务异常！',
                icon: "none",
                duration: 2000,
            });
        }
    })
}
//查询全部海报
const getgoodsPosterall = (callback)=>{
    request({
        url: "/mall/goodsPoster/all",
        method: "get",
        success: function (res) {
            callback(res);
        },
        fail: function (err) {
            //console.log(111, err)
            wx.showToast({
                title: err.errMsg,
                icon: "none",
                duration: 2000,
            });
        },
    });
}
module.exports = {
    getGoodsQrCode,
    addBack,
    getMyBankList,
    getCurrentLottery,
    startLottery,
    getCommodityCategory,
    tAgentAdd,
    getMyAgentList,
    getMyCustomerList,
    getAgentTypeList,
    delBankCard,
    getOverallBalance,
    getWithdraw,
    bindSubmit,
    getMinimumMoney,
    getGoodpercent,
    returnMoney,
    getgoodsPosterall
}